<link rel="stylesheet" type="text/css" href="../addons/jy_weishop/custom/templates/mobile/css/coupon.css?v=2.0.0">
<link rel="stylesheet" type="text/css" href="../addons/jy_weishop/custom/templates/mobile/css/coupon-new.css?v=2022030302">
<style>
.coupon-item .coupon-right .usetime {
    font-size: 0.5rem;
}
</style>
<div ng-if="!pagedata.showgetcoupon">
	<div class="coupon-picker option-picker">
		<div class="option-picker-inner coupon-picker">
			<div ng-if="pagedata.coupons.length<1" class="content-empty">
				<i class='icon icon-searchlist'></i><br/> 没有任何可用于本商品的优惠券!<br/><a ng-click="pagedata.showgetcoupon=true;pagedata.getcoupon()" class='btn btn-banf btn-default-o external'>去领券</a>
			</div>
			<div ng-if="pagedata.wxcards.length>0 || pagedata.coupons.length>0" class="coupon-list mini">
					<div ng-repeat="wxcard in pagedata.wxcards" class="coupon-item  {{wxcard.color}}">
						<div class="coupon-dots">
							<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
						</div>
						<div class="coupon-left">
							<div class="single" ng-if="wxcard.code_type =='CASH'"><span style="font-size:0.6rem">￥</span>{{wxcard.backmoney}}</div>
							<div class="single" ng-if="wxcard.code_type !='CASH'">{{wxcard.backmoney}}</div>
						</div>
						<div class="coupon-right">
							<div class="title">{{wxcard.title}}</div>
							<div class="usetime">
								<div class="text">有效期:{{wxcard.timestr}}</div>
							</div>
						</div>
						<div class="coupon-after">
							<div ng-click="pagedata.post.couponid=wxcard.id" ng-class="{'coupon-btn':1,'active':pagedata.post.couponid==wxcard.id}">选择</div>
						</div>
					</div>
				<div ng-repeat="coupon in pagedata.coupons" class="coupon-item  {{coupon.color}} ">
					<div class="coupon-dots">
						<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
					</div>
					<div class="coupon-left">
						<div class="single" ng-if="coupon.coupon.backtype == '0'"><span style="font-size:0.6rem">￥</span>{{coupon.deduct}}</div>
						<div class="single" ng-if="coupon.coupon.backtype == '1'">{{coupon.discount}}折</div>
						<div class="single" ng-if="coupon.coupon.backtype == '2'">立返</div>
					</div>
					<div class="coupon-right" style="padding:0.3rem 0.5rem">
						<div class="title">{{coupon.title}}</div>
						<div class="gray" style="font-size:0.6rem">{{coupon.coupon.title5}}</div>
						<div class="usetime">
							<div class="text">{{coupon.coupon.title4}}</div>
						</div>
					</div>
					<div class="coupon-after" style="padding-right:0">
						<div ng-click="pagedata.post.couponid=coupon.id;pagedata.post.backtype=coupon.coupon.backtype;pagedata.post.discount=coupon.discount;pagedata.post.deduct=coupon.deduct;pagedata.post.title5=coupon.coupon.title5" ng-class="{'coupon-btn':1,'active':pagedata.post.couponid==coupon.id}">选择</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div ng-if="pagedata.post.couponid" class="fui-navbar" style="z-index: 999">
			<a href="javascript:" ng-click="pagedata.checkcoupon(0)" class="nav-item btn btn-default btn-cancel"  style="color: #666">不使用优惠券</a>
			<a href="javascript:" ng-click="pagedata.checkcoupon(1)" class="nav-item btn btn-danger btn-confirm">确定使用</a>
	</div>
</div>
<div ng-if="pagedata.showgetcoupon">
	<div class="coupon-picker option-picker" style="max-height:25rem">
		<div class="option-picker-inner coupon-picker">
			<div ng-if="pagedata.getcoupons.length<1" class="content-empty">
				<i class='icon icon-searchlist'></i><br/> 没有任何可领取的优惠券!
			</div>
			<div ng-if="pagedata.getcoupons.length>0" class="coupon-list mini">
				<div ng-repeat="coupon in pagedata.getcoupons" class="coupon-item  {{coupon.color}} ">
					<div class="coupon-dots">
						<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
					</div>
					<div class="coupon-left">
						<div class="single" ng-if="coupon.backtype == '0'"><span style="font-size:0.6rem">￥</span>{{coupon.deduct}}</div>
						<div class="single" ng-if="coupon.backtype == '1'">{{coupon.discount}}折</div>
						<div class="single" ng-if="coupon.backtype == '2'">立返</div>
					</div>
					<div class="coupon-right" style="padding:0.3rem 0.5rem">
						<div class="title">{{coupon.title}}</div>
						<div class="gray" style="font-size:0.6rem">{{coupon.title5}}</div>
						<div class="usetime">
							<div class="text">{{coupon.title4}}</div>
						</div>
					</div>
					<div class="coupon-after" style="padding-right:0">
						<div ng-click="pagedata.getonecoupon(coupon.id)" ng-class="{'coupon-btn':1,'active':pagedata.post.couponid==coupon.id}">领取</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div ng-if="pagedata.getcoupons.length>0" class="fui-navbar" style="z-index: 999">
			<a href="javascript:" ng-click="pagedata.getallcoupon()" class="nav-item btn btn-danger btn-confirm">全部领取</a>
	</div>
</div>
<script language='javascript'>
scope.pagedata.getcoupon=function(){
	var merchid=0;
	if(scope.pagedata.order){
		var merchid=scope.pagedata.order.merchid?scope.pagedata.order.merchid:0;
	}
	scope.get('jy_weishop/coupon.index/main/isallcan=1&merchid='+merchid,function(res){
		scope.pagedata.getcoupons=res.list;
		scope.pagedata.couponids=res.couponids;
		scope.$evalAsync();
	});
}
scope.pagedata.getmycoupon_ing=function(){
	scope.post_json('jy_weishop/coupon.index/getmycoupon_ing/',scope.pagedata.order,function(res){
		scope.pagedata.coupons=res.coupons;
		scope.pagedata.couponcount=res.couponcount;
		scope.pagedata.order.coupon_de_price=res.coupon_de_price;
		scope.pagedata.item.couponid=res.couponid;
		scope.pagedata.showgetcoupon=false;
		scope.$evalAsync();
	});
}
scope.pagedata.getonecoupon=function(couponid){
	scope.post_json('jy_weishop/coupon.detail/getcoupon/',{'id':couponid,'nogoback':1},function(res){
		scope.pagedata.getmycoupon_ing();
		scope.message('领取成功！');
	});
}
scope.pagedata.getallcoupon=function(){
	scope.post_json('jy_weishop/coupon.index/getall/',{'couponids':scope.pagedata.couponids,'nogoback':1},function(res){
		scope.pagedata.getmycoupon_ing();
		scope.message('领取成功！');
	});
}
</script>